const {merge} = require('webpack-merge');
const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const baseWebpackConfig = require('./webpack.common');

const resolve = function (dir) {
  return path.resolve(__dirname, dir);
};

module.exports = merge(baseWebpackConfig, {
  mode: 'production',
  plugins: [
    new CleanWebpackPlugin(),
    new CopyWebpackPlugin({
      patterns: [
        {
          from: resolve('public'),
          globOptions: {
            ignore: ['.*', '**.html'],
          },
        },
      ],
    }),
    new HtmlWebpackPlugin({
      title: 'vue-app-base',
      url: '',
      filename: 'index.html',
      template: 'public/index.html',
      inject: true,
      minify: {
        removeComments: true,
        collapseWhitespace: true,
        removeAttributeQuotes: true
      }
    }),
  ],
});
